<template>
  <div>
    <avue-form :option="option" v-model="form" @submit="submit">
    </avue-form>
    <!-- 创建档案 -->
    <el-dialog title="健康档案条纹码" :visible.sync="tmCodeVisible">
      <div style="text-align:center" ref="print">
        <svg id="tmcode" style="width:24px;height:12px"></svg>
        <!-- <p style="text-align:center">张艾琳</p> -->
      </div>
      <span class="dialog-footer" style="margin-left:45%">
        <el-button type="primary" @click="myprint">打印</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { setStore, getStore } from '@/util/store'
import { updateObj } from '@/api/cust/health/jkdn'
import option from '@/const/cust/health/jkdn'
import JsBarcode from 'jsbarcode'
export default {
  data() {
    return {
      option: option,
      tmCodeVisible: false,
      form: {}
    }
  },
  watch: {},
  computed: {
    ...mapGetters(['permissions'])
  },
  created() {
    this.form = getStore({ name: 'jkdn' })
  },
  methods: {
    myprint() {
      this.$print(this.$refs.print) // 使用
    },
    submit() {
      this.form.cwhmc = this.form.$cwhmcid
      updateObj(this.form).then(res => {
        if (!this.validatenull(res.data)) {
          setStore({ name: 'jkdn', content: res.data })
          this.$message({
            showClose: true,
            message: '保存成功',
            type: 'success'
          })
          this.tmCodeVisible = true
          setTimeout(() => {
            JsBarcode('#tmcode', res.data.tmcode, {
              height: 65,
              width: 1.4,
              text: res.data.name + ' ' + res.data.tmcode,
              fontSize: 16
            })
          }, 300)
        }
      })
    }
  }
}
</script>